package com.example.jnnews;

import com.google.gson.annotations.SerializedName;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Article {
    @SerializedName("title")
    private String title;

    @SerializedName("content")
    private String content;

    @SerializedName("author")
    private String author;

    @SerializedName("publishTime")
    private Date publishTime;

    // 必须包含无参构造器
    public Article() {}

    public Article(String title, String content, String author) {
        this.title = title;
        this.content = content;
        this.author = author;
        this.publishTime = new Date();
    }

    // Getter 方法
    public String getTitle() { return title; }
    public String getContent() { return content; }
    public String getAuthor() { return author; }
    public Date getPublishTime() { return publishTime; }

    // 格式化时间显示
    public String getFormattedTime() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA).format(publishTime);
    }
}